package com.yadang.choujiang;

import java.text.DecimalFormat;
import java.util.Random;

/**
 * @author: 亚当
 * @date: 2023年05月14日 22:50
 * @package: com.yadang.choujiang
 * @Description: TODO
 */
public class RandomNumber  {
    // 1.1到1.3中间的随机数[1.1,1.3]
    public static void main(String[] args) {
        for (int i=0;i<100;i++){
            double randomValue = getRandomNumberInRange(1.1, 1.3);
            //System.out.println("生成的随机数是: " + randomValue);
            System.out.println("生成的随机数是: " + new DecimalFormat("#.0#").format(randomValue));
        }
    }

    private static double getRandomNumberInRange(double min, double max) {
        if (min >= max) {
            throw new IllegalArgumentException("max must be greater than min");
        }

        Random r = new Random();
        return min + (max - min) * r.nextDouble();
    }
}
